//闭包来封装http
function Http(){
    var xmlhttp = new XMLHttpRequest();
    var _url = "http://localhost:3000";
    return {
        request:function({method,url,data,success}){
            xmlhttp.open(method, _url+url); //异步
            if(method =='GET'){
                xmlhttp.send(); //发送
            }else {
                xmlhttp.setRequestHeader("Content-Type","application/json");  //请求头
                xmlhttp.send(data); //发送
            };
            xmlhttp.onreadystatechange = function() { 
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    success(xmlhttp.responseText)   
                }else {

                }
            }
        }
    }
}
